package leetcode100;

import exer.ListNode;

/**
 * @author shkstart
 * @create 2022-11-13-17:33
 */
public class Num2 {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {


        ListNode sum = new ListNode(0);
        ListNode head = sum;
        int addOne = 0;

        while (l1 != null || l2 != null||addOne==1) {
            int val1;
            int val2;
            if(l1!=null){
                 val1 = l1.val;
            }else {
                 val1 = 0;
            }
            if(l2!=null){
                 val2 = l2.val;
            }else {
                 val2 = 0;
            }
            int rr = val1 + val2 + addOne;
            addOne = rr>=10? 1:0;


            sum.next = new ListNode(rr%10);
            sum = sum.next;

            if (l1 != null) {
                l1 = l1.next;
            }
            if (l2 != null) {
                l2 = l2.next;
            }



        }
        return head.next;

    }

}
